#include "StdAfx.h"
#include "LitEditorSettingsDialog.h"
#include "LitEditorInstance.h"

namespace Lit
{
	namespace Editor
	{
		void SettingsDialog::ogreConfigured( const std::string &page, const std::string &name, const std::string &val )
		{
		}
		SettingsMap SettingsDialog::ConfigureOgre( QWidget * parent, Instance * instance, const std::string &title )
		{
			SettingsDialog *dlg = new SettingsDialog(parent);
			SettingsMap settings;
			settings.setValue( SettingsValue( "Ambient Light", Ogre::StringConverter::toString( instance->getSceneManager()->getAmbientLight() ), ST_COLOR ) );
			settings.setValue( SettingsValue( "Camera Near Clip", Ogre::StringConverter::toString( instance->getSceneCamera()->getNearClipDistance() ), ST_FLOAT ));
			settings.setValue( SettingsValue( "Camera Far Clip", Ogre::StringConverter::toString( instance->getSceneCamera()->getFarClipDistance() ), ST_FLOAT ));
			settings.setValue( SettingsValue( "Camera FOVy", Ogre::StringConverter::toString( instance->getSceneCamera()->getFOVy() ), ST_FLOAT ) );
			settings.setValue( SettingsValue( "Camera Focal Length", Ogre::StringConverter::toString( instance->getSceneCamera()->getFocalLength() ), ST_FLOAT ) );
			
			SettingsMap new_settings( dlg->exec(settings, title) );
			if( settings != new_settings )
			{				
				settings = new_settings;
				instance->getSceneManager()->setAmbientLight( Ogre::StringConverter::parseColourValue( settings.getValue("Ambient Light")->second ) );
				instance->getSceneCamera()->setNearClipDistance( Ogre::StringConverter::parseReal( settings.getValue("Camera Near Clip")->second ) );
				instance->getSceneCamera()->setFarClipDistance( Ogre::StringConverter::parseReal( settings.getValue("Camera Far Clip")->second ) );
				instance->getSceneCamera()->setFOVy( Ogre::StringConverter::parseAngle( settings.getValue("Camera FOVy")->second ) );
				instance->getSceneCamera()->setFocalLength( Ogre::StringConverter::parseReal( settings.getValue("Camera Focal Length")->second ) );
			}
			delete dlg, dlg=NULL;
			return settings;
		}
	};
};